﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Red.Toolkit.Profiler.Logic;

namespace Red.Toolkit.Profiler.Logic.Interpreters
{
    public abstract class ProfilerDataInterpreter
    {
        private string _Name;
        private string _FilePath;
        protected ProfilerData _Data;
        protected ProfilerDataView _TraceView;
        private ProfilerViewStyle _TraceStyle;

        public ProfilerDataInterpreter(string name, string path, ProfilerData data)
        {
            _Name = name;
            _FilePath = path;
            _Data = data;
            _TraceView = null;
            _TraceStyle = new ProfilerViewStyle();
        }

        public string DisplayName
        {
            get
            {
                return _Name + " (" + _FilePath + ") " + Length.ToString("0.00") + "s";
            }
        }

        public ProfilerViewStyle Style
        {
            get
            {
                return _TraceStyle;
            }
        }

        public ProfilerDataView View
        {
            get
            {
                return _TraceView;
            }
        }

        public Double Length
        {
            get
            {
                return _Data.Length;
            }
        }

        public bool Process()
        {
            if (_TraceView == null)
            {
                _TraceView = new ProfilerDataView();
                if (!AnalyzeRawData(_Data, _TraceView))
                    return false;
            }

            return true;
        }

        protected abstract bool AnalyzeRawData(ProfilerData data, ProfilerDataView view);

        public abstract string GetDescription(IList<ProfilerDataView.Event> events, Double timeLength);

        public abstract string[] GetGraphNames();

        public abstract string[] GetStatGraphsNames();

        public abstract string[] GetBlockHitDataNames();            
    }
}
